# coding=utf-8
import random
from datetime import timedelta

from django.utils import timezone

from social.account.models import User
from social.utils.celery_app import app


@app.task()
def random_robot_active():
    users = list(User.objects.filter(first_name='robot'))
    users = random.sample(users, int(len(users) / 2))
    for u in users:
        random_time = timezone.now() - timedelta(hours=random.randint(1, 80))
        if u.last_active < random_time:
            u.last_active = random_time
            u.save()
